package com.ssy.lingxi.common.constant.product;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 商品类型 - S2B功能使用
 *
 * @author lxc
 * @version 2.0.0
 * @date 2022/3/4
 */
public enum CommodityS2BTypeEnum {

    SELF_OPERATED_COMMODITY(1, "自营商品"),
    UPPER_SUPPLY_COMMODITY(2, "上游供应商品");

    private Integer code;
    private String message;

    CommodityS2BTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    /**
     * 针对字段类型为Integer
     * @return
     */
    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    /**
     * 针对字段类型为String
     * @return
     */
    public String getCHMessage() {
        return this.message;
    }

    public static String getNameByCode(Integer code) {
        CommodityS2BTypeEnum typeEnum = Arrays.stream(CommodityS2BTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return null == typeEnum ? "" : LanguageHolder.getName(CommodityS2BTypeEnum.class, typeEnum.getCode());
    }
}
